package com.fulu.netty.luban.nio;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("demo3.txt");
        FileChannel channel = fileInputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            int read = channel.read(buffer);
            if(read == -1){
                break;
            }
            System.out.println(read);
            buffer.flip();
            // array 方法直接返回数组
            String s = new String(buffer.array());
            System.out.println(s);

        }
    }
}
